package com.slipper.codeless.trigger;

import com.slipper.system.codeless.bo.DataModelBO;
import com.slipper.system.codeless.service.DataModelService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class TriggerListener implements ApplicationRunner {
    private static final Logger logger = LoggerFactory.getLogger(TriggerListener.class);

    @Resource
    private DataModelService dataModelService;
    @Resource
    private CodelessTrigger codelessTrigger;

    @Override
    public void run(ApplicationArguments args) {
        this.loadCodelessTrigger();
    }

    public void loadCodelessTrigger() {
        dataModelService.queryList(new DataModelBO()).forEach(dataModel -> codelessTrigger.updateTrigger(dataModel));
        logger.info("数据模型触发器已加载...");
    }
}
